package my.edu.ai.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.core.JsonProcessingException;
import my.edu.ai.entity.AiChat;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ChatMemoryServiceImpl implements ChatMemory {
    @Autowired
    private IAiChatService aiChatService;

    @Override
    public void add(String conversationId, List<Message> messages) {
        try {
            aiChatService.addMessages(conversationId,messages);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<Message> get(String conversationId, int lastN) {
        return aiChatService.getMessagesByConversationId(conversationId, lastN);
    }

    @Override
    public void clear(String conversationId) {

    }
}
